<template>
	<view class="container" :style="{...navStyle}">
		<view class="headBox" :style="{height:navHeight+'rpx',backgroundColor:navBackgroundColor}">
			<view class="wx-head-mod" :style="{height:navHeight+'rpx',backgroundColor:navBackgroundColor}">
				<view class="wx-head-mod-nav" :style="{height:navigationBarHeight+'rpx',top:statusBarHeight+'rpx'}">
					<view class="wx-head-mod-nav-content"
						:style="{height:customHeight+'rpx',justifyContent:textAlign === 'center'?'center':'left'}">
						<!-- 返回按钮 -->
						<view class="wx-head-mod-nav-content-back" :style="{display:isBackShow?'flex':'none'}"
							@click="$back">
							<view class="wx-head-mod-nav-content-back-img">
								<image class="otmmb"
									:src="$getImgSrc(backIcon || (backType == 1 ? defaultBlack : defaultWhite))"
									mode="widthFix">
								</image>
							</view>
						</view>

						<view class="wx-head-mod-nav-content-mian" :style="{
								width:navTextWidth,
							lineHeight:customHeight + 'rpx',
							paddingLeft:textPaddingLeft*scaleFactor+'rpx',
							fontSize:fontSize+'rpx',
							fontWeight:fontWeight,
							color:titleColor
							}">
							<text>{{textContent}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="slot-view">
			<slot></slot>
		</view>
	</view>
</template>

<script>
	const app = getApp()
	import {
		systemInfo
	} from '@/common/getSystem.js'
	export default {
		name: "HeadView",
		props: {
			// 文本区域位置 left：左  center：中  
			textAlign: {
				type: String,
				default: 'left'
			},
			// 文本区内容
			textContent: {
				type: String,
				default: '标题'
			},
			// 文本区离左边的距离
			textPaddingLeft: {
				type: Number,
				default: 0
			},
			// 是否需要返回按钮
			isBackShow: {
				type: Boolean,
				default: false
			},
			backIcon: {
				type: String,
				default: ''
			},
			// 返回类型
			backType: {
				type: Number,
				default: 2
			},
			// 文本区字体大小
			fontSize: {
				type: Number,
				default: 40
			},
			// 文本区字体粗细
			fontWeight: {
				type: Number,
				default: 0
			},
			// 文本区返回按钮图片宽
			backImageWidth: {
				type: Number,
				default: 12 //px
			},
			// 文本区返回按钮图片高
			backImageHeight: {
				type: Number,
				default: 24 //px
			},
			// 导航栏整体背景颜色
			navBackgroundColor: {
				type: String,
				// default: '#2476F9'
			},
			// 标题字体颜色
			titleColor: {
				type: String,
				default: '#000000',
			},
			// 导航栏整体附加样式
			navStyle: {
				type: Object,
				default: () => {
					return {}
				}
			},

		},
		computed: {
			// 文本区宽度
			navTextWidth() {
				if (this.textAlign === 'center') {
					return (this.windowWidth - (this.windowWidth - this.menubarLeft) * 2) + 'rpx'
				} else {
					return this.menubarLeft + 'rpx'
				}
			},
			// 文本区paddingLeft
			textPaddingleft() {
				if (this.textAlign === 'center') {
					return '0'
				} else {
					return this.textPaddingLeft + 'rpx'
				}
			}
		},
		data() {
			return {
				statusBarHeight: 0, //状态栏高度
				navHeight: 0, //头部导航栏总体高度
				navigationBarHeight: 0, //导航栏高度
				customHeight: 0, //胶囊高度
				scaleFactor: 0, //比例系数
				menubarLeft: 0, //胶囊定位的左边left
				windowWidth: 0,
				// 返回图标 黑
				defaultBlack: '/static/parentsPc/index/back.png',
				// 返回图标 白
				defaultWhite: '/static/parentsPc/index/backWhite.png'
			};
		},
		methods: {
			backEvent() {
				uni.navigateBack({
					delta: 1
				})
			}
		},
		created() {
			/* 获取设备信息 */
			const SystemInfomations = systemInfo()
			/* 通用平台 */
			this.statusBarHeight = SystemInfomations.statusBarHeight //状态栏高度
			this.scaleFactor = SystemInfomations.scaleFactor //比例系数
			this.windowWidth = SystemInfomations.windowWidth //当前设备的屏幕宽度
			/* 微信小程序平台 */
			// #ifdef MP-WEIXIN
			this.navHeight = SystemInfomations.navHeight + SystemInfomations.statusBarHeight //头部导航栏总高度
			this.navigationBarHeight = SystemInfomations.navHeight //头部导航栏高度
			this.customHeight = SystemInfomations.menuButtonHeight //胶囊高度
			this.menubarLeft = SystemInfomations.menuButtonLeft //胶囊左边界距离左上角的距离
			// #endif

		}
	}
</script>

<style>
	.headBox {
		position: relative;
		z-index: 2;
	}

	.wx-head-mod {
		box-sizing: border-box;
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
	}

	.wx-head-mod-nav {
		box-sizing: border-box;
		width: 100%;
		position: absolute;
		left: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		padding-left: 15rpx;
	}

	.wx-head-mod-nav-content {
		box-sizing: border-box;
		width: 100%;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		position: relative;
	}

	.wx-head-mod-nav-content-mian {
		flex: 1;
		box-sizing: border-box;
		height: 100%;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
		display: flex;
		justify-content: center;
		align-items: center;
		/* background-color: red; */
		/* border: 1rpx solid red; */
	}

	.wx-head-mod-nav-content-back {
		box-sizing: border-box;
		width: 60rpx;
		height: 100%;
		/* border: 1rpx solid red; */
		position: absolute;
		left: 0;
		top: 0;
		display: flex;
		align-items: center;
	}

	.wx-head-mod-nav-content-back-img {
		box-sizing: border-box;
		width: 60rpx;
		height: 60rpx;
	}

	.otmmb {
		width: 60rpx;
		height: 60rpx;
	}

	.other-head-mod {
		box-sizing: border-box;
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
	}

	.other-head-mod-mian {
		box-sizing: border-box;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: left;
		left: 0;
		bottom: 0;
	}

	.other-head-mod-mian-back {
		box-sizing: border-box;
		height: 100%;
		width: 60rpx;
		position: absolute;
		left: 32rpx;
		top: 0;
		display: flex;
		align-items: center;
	}

	.other-head-mod-mian-back-img {
		width: 30rpx;
		height: 30rpx;
	}

	.otmmb {}

	.other-head-mod-mian-title {
		box-sizing: border-box;
		height: 100%;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}
</style>
